package com.re6g3y.game.entity;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

public class Ship extends TextureEntityWithBody {
    public final Vector2 target=new Vector2();

    public void lookToTarget(){
        Vector2 pointTo=new Vector2(MathUtils.sin(body.getAngle()),-MathUtils.cos(body.getAngle()));
        Vector2 toCenter=target.cpy().sub(body.getPosition());
        body.applyAngularImpulse(body.getMass()*(-toCenter.angle(pointTo)/3),false);
    }

    public void lookToTarget(Vector2 target){
        this.target.set(target);
        lookToTarget();
    }

    public void moveForward(){
        Vector2 pointTo=new Vector2(MathUtils.sin(body.getAngle()),-MathUtils.cos(body.getAngle()));
        body.applyForceToCenter(pointTo.scl(body.getMass()*1000),false);
    }

    public void stabilize(){
        body.applyAngularImpulse(5*body.getMass()*(-body.getAngularVelocity()),false);
    }
}
